SELECT T.ID, T.SITE_ID, T.STATE_ID, T.PARENT_ID, T.TYPE_ID, T.CODE, T.NAME, T.ORDER_NUM, T.BEGIN_DA_TI, T.END_DA_TI,
  T.URL, T.TARGET, T.DATA_OPTIONS
FROM FD_NAVIGATION T
<#if (PARENT_ID!) != ''>
WHERE T.PARENT_ID = :PARENT_ID
<#else>
WHERE T.PARENT_ID IS NULL
</#if>
<#if (SITE_ID!) != ''>
AND T.SITE_ID      = :SITE_ID
<#else>
AND EXISTS
  (SELECT 1
  FROM FD_SITE ES
  JOIN FD_SITE_DE ESD ON ( ESD.ENTITY_ID = ES.ID )
  WHERE ES.ID                            = T.SITE_ID
  )
</#if>
<#if (TYPE_ID!) != ''>
AND T.TYPE_ID      = :TYPE_ID
<#else>
AND EXISTS
  (SELECT 1
  FROM FD_DICTIONARY ED
  JOIN FD_DICTIONARY_TY EDT ON ( EDT.ID = ED.TYPE_ID )
  WHERE EDT.CODE                        = 'NAVIGATION_TY'
  AND ED.CODE                           = :TYPE_CODE
  AND ED.ID                             = T.TYPE_ID
  )
</#if>
AND EXISTS
  (SELECT 1
  FROM FD_DICTIONARY ED
  JOIN FD_DICTIONARY_TY EDT ON ( EDT.ID = ED.TYPE_ID )
  WHERE EDT.CODE                        = 'NavigationState'
  AND ED.CODE                           = '1'
  AND ED.ID                             = T.STATE_ID
  )
ORDER BY T.ORDER_NUM